const path = require('path')

const isProduction = process.env.NODE_ENV === 'production'

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: './',
  assetsDir: 'static',
  productionSourceMap: false,
  devServer: {
    proxy: {
      '/Api': {
        target: 'http://121.5.64.87:8090',
        changeOrigin: true,
        pathRewrite: {
          '/Api': ''
        }
      }
    }
  },

  chainWebpack: config => {
    // 配置别名
    config.resolve.alias.set('@', resolve('src'))

    if (isProduction) {
      // 移除预加载 减小请求个数
      config.plugins.delete('prefetch')
      config.plugins.delete('preload')
    }
  },

  configureWebpack: config => {
    if (isProduction) {
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
      config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
    }
  }
}
